import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import GlobalEvent from './Global/GlobalEvent';
import LevelManager from './managers/LevelManager';

@ccclass('createMonster')
export class createMonster extends Component {
    @property(Prefab)
    monsterPrefab: Prefab;

    @property(Node)
    monsters: Node;

    onLoad(): void {
        globalThis.createM = this;
        // this.createMonsters()
        GlobalEvent.on('createM', () => { this.createMonsters() }, this)
    }

    start() {
        // console.log('createMonsters的start执行了');
    }

    // 创建怪物
    createMonsters() {
        this.addMonsterDate()
        let monsterShu = 2;
        if (this.monsters.children.length > 1) return;
        for (let i = 0; i <= monsterShu; i++) {
            let monsterNode = instantiate(this.monsterPrefab);
            let pos = new Vec3(400, 100 + i * 110, i + 1); // 设置怪物的位置
            monsterNode.setPosition(pos);
            this.monsters.addChild(monsterNode); // 将怪物节点添加到场景
        }
    }

    //提升怪物的数值 获取关卡数进行处理
    addMonsterDate() {
        const levelManager = LevelManager.getInstance();
        let level = levelManager.getLevel()
        // console.log('level = ', level);

    }
}

